package util.nlp;

import java.io.File;
import java.net.URL;
import java.util.Arrays;

import net.didion.jwnl.JWNLException;

import edu.smu.tspell.wordnet.NounSynset;
import edu.smu.tspell.wordnet.Synset;
import edu.smu.tspell.wordnet.WordNetDatabase;
import edu.smu.tspell.wordnet.impl.file.synset.NounReferenceSynset;


import rita.wordnet.*;
import processing.core.*; 
public class WordNetWrapper {

	/**
	 * @param args
	 */
	
	private WordNetDatabase database =null;
	public WordNetWrapper(){
		
		System.setProperty("wordnet.database.dir", "/home/sergio/projects/WordNet-3.0/dict");
		database = WordNetDatabase.getFileInstance();
		
	}
	
	
	public static void test (){
		
		String wordForm = "Manhattan";
		//  Get the synsets containing the wrod form
		WordNetDatabase database = WordNetDatabase.getFileInstance();
		
		Synset[] synsets = database.getSynsets(wordForm);
		
		//  Display the word forms and definitions for synsets retrieved
		if (synsets.length > 0)
		{
			System.out.println("The following synsets contain '" +
					wordForm + "' or a possible base form " +
					"of that text:");
			for (int i = 0; i < synsets.length; i++)
			{
				
				NounReferenceSynset  noun = new NounReferenceSynset(synsets[i].getDefinition(),null,null,null, 0,0 );

				System.out.println("");
				String[] wordForms = synsets[i].getWordForms();
				for (int j = 0; j < wordForms.length; j++)
				{
					System.out.print((j > 0 ? ", " : "") +
							wordForms[j]);
				}
				System.out.println(": " + synsets[i].getDefinition());
				System.out.println("type:" + noun.getHypernyms());
			}
		}
		else
		{
			System.err.println("No synsets exist that contain " +
					"the word form '" + wordForm + "'");
		}

		   

		
		
	}
	
	public String getSemanticClass(String lemma) {

		String semantic_class = "";
		Synset[] synsets = database.getSynsets(lemma);
		
		
		if (synsets.length > 0) {
			System.out.println("The following synsets contain '" + lemma
					+ "' or a possible base form " + "of that text:");
			for (int i = 0; i < synsets.length; i++) {
				System.out.println("");
				String[] wordForms = synsets[i].getWordForms();
				for (int j = 0; j < wordForms.length; j++) {
					System.out.print((j > 0 ? ", " : "") + wordForms[j]);
				}
				System.out.println(": " + synsets[i].getDefinition());
				System.out.println("type:" + synsets[i].getType());
				
			}
		} else {
			System.err.println("No synsets exist that contain "
					+ "the word form '" + lemma + "'");
		}

		return null;

	}
	
	
	public static void main(String[] args) throws JWNLException {
		// TODO Auto-generated method stub
		// System.setProperty("wordnet.database.dir",
		// "/home/sergio/projects/WordNet-3.0/dict");
		// test();

		String word, hypos[];
		String[] tmp = null;

		RiWordnet wordnet = new RiWordnet(null,
				"/home/sergio/projects/WordNet-3.0/dict/");

		int[] syn = wordnet.getSenseIds("phonograph record", RiWordnet.NOUN);
		for (int i = 0; syn != null && i < syn.length; i++) {

			System.out.println(syn[i]);
			String tree1 [] = wordnet.getHypernymTree(syn[i]);
			String[] tree = wordnet.getExamples(syn[i]);

tree= tree1;


			for (int j = 0; tree != null && j < tree.length; j++) {

				System.out.print(tree[j] + "\t");

			}
			System.out.println("");

		}

	}

}
